// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   WebSelUtil.java

package com.vandagroup.common.util.web;

import com.vandagroup.common.util.Paras;
import java.io.PrintStream;
import java.util.*;
import javax.servlet.jsp.JspWriter;

// Referenced classes of package com.vandagroup.common.util.web:
//            WebSelXmlReader

public class WebSelUtil
{

    public String type;
    public String name;
    public HashMap enum_;
    public HashSet values;
    public Vector order;
    public String onBlur;
    public String onChange;
    public String onFocus;
    public String onClick;
    public String className;
    public String style;
    public boolean multiple;
    public String rows;
    public int unitsPerRow;
    public boolean addNullOption;
    public boolean disabled;

    public WebSelUtil()
    {
        type = null;
        name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
    }

    public WebSelUtil(String type)
    {
        this.type = null;
        name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
    }

    public WebSelUtil(String type, String name)
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
    }

    public WebSelUtil(String type, String name, HashMap enum_)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
    }

    public WebSelUtil(String type, String name, HashMap enum_, Vector order)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        values = null;
        this.order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        setOrder(order);
    }

    public WebSelUtil(String type, String name, String ary[][])
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        values = null;
        this.order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        HashMap enum_ = new HashMap();
        Vector order = new Vector();
        for(int i = 0; i < ary.length; i++)
        {
            order.addElement(ary[i][0]);
            enum_.put(ary[i][0], ary[i][1]);
        }

        setType(type);
        setName(name);
        setEnum_(enum_);
        setOrder(order);
    }

    public WebSelUtil(String type, String name, HashMap enum_, boolean addNullOption)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        setAddNullOption(addNullOption);
    }

    public WebSelUtil(String type, String name, HashMap enum_, HashSet values)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        setValues(values);
    }

    public WebSelUtil(String type, String name, HashMap enum_, HashSet values, boolean addNullOption)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        setValues(values);
        setAddNullOption(addNullOption);
    }

    public WebSelUtil(String type, String name, HashMap enum_, String values[])
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        HashSet hs = new HashSet();
        for(int i = 0; i < values.length; i++)
            hs.add(values[i]);

        setValues(hs);
    }

    public WebSelUtil(String type, String name, HashMap enum_, String values[], boolean addNullOption)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        HashSet hs = new HashSet();
        for(int i = 0; i < values.length; i++)
            hs.add(values[i]);

        setValues(hs);
        setAddNullOption(addNullOption);
    }

    public WebSelUtil(String type, String name, HashMap enum_, String value)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        HashSet hs = new HashSet();
        hs.add(value);
        setValues(hs);
    }

    public WebSelUtil(String type, String name, HashMap enum_, String value, boolean addNullOption)
    {
        this.type = null;
        this.name = null;
        this.enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(enum_);
        HashSet hs = new HashSet();
        hs.add(value);
        setValues(hs);
        setAddNullOption(addNullOption);
    }

    public WebSelUtil(String type, String name, String paraName)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        setValues(getDefaultValues(paraName));
        setOrder(getXMLOrders(paraName));
    }

    public WebSelUtil(String type, String name, String paraName, boolean addNullOption)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        setValues(getDefaultValues(paraName));
        setAddNullOption(addNullOption);
        setOrder(getXMLOrders(paraName));
    }

    public WebSelUtil(String type, String name, String paraName, HashSet values)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        setValues(values);
    }

    public WebSelUtil(String type, String name, String paraName, HashSet values, boolean addNullOption)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        setValues(values);
        setAddNullOption(addNullOption);
    }

    public WebSelUtil(String type, String name, String paraName, String values[])
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        HashSet hs = new HashSet();
        for(int i = 0; i < values.length; i++)
            hs.add(values[i]);

        setValues(hs);
    }

    public WebSelUtil(String type, String name, String paraName, String values[], boolean addNullOption)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        this.values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        HashSet hs = new HashSet();
        for(int i = 0; i < values.length; i++)
            hs.add(values[i]);

        setValues(hs);
        setAddNullOption(addNullOption);
    }

    public WebSelUtil(String type, String name, String paraName, String value)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        HashSet hs = new HashSet();
        hs.add(value);
        setValues(hs);
    }

    public WebSelUtil(String type, String name, String paraName, String value, boolean addNullOption)
        throws Exception
    {
        this.type = null;
        this.name = null;
        enum_ = null;
        values = null;
        order = null;
        onBlur = null;
        onChange = null;
        onFocus = null;
        onClick = null;
        className = null;
        style = null;
        multiple = false;
        rows = null;
        unitsPerRow = 3;
        this.addNullOption = false;
        disabled = false;
        setType(type);
        setName(name);
        setEnum_(getParaEnum_(paraName));
        HashSet hs = new HashSet();
        hs.add(value);
        setValues(hs);
        setAddNullOption(addNullOption);
    }

    public String getName()
    {
        return name;
    }

    public String getType()
    {
        return type;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public void setType(String type)
    {
        this.type = type;
    }

    public HashMap getEnum_()
    {
        return enum_;
    }

    public HashSet getValues()
    {
        return values;
    }

    public void setEnum_(HashMap enum_)
    {
        this.enum_ = enum_;
    }

    public void setValues(HashSet values)
    {
        this.values = values;
    }

    public String getOnBlur()
    {
        return onBlur;
    }

    public String getOnChange()
    {
        return onChange;
    }

    public String getOnFocus()
    {
        return onFocus;
    }

    public void setOnBlur(String onBlur)
    {
        this.onBlur = onBlur;
    }

    public void setOnChange(String onChange)
    {
        this.onChange = onChange;
    }

    public void setOnFocus(String onFocus)
    {
        this.onFocus = onFocus;
    }

    public String getClassName()
    {
        return className;
    }

    public boolean isMultiple()
    {
        return multiple;
    }

    public String getStyle()
    {
        return style;
    }

    public void setClassName(String className)
    {
        this.className = className;
    }

    public void setMultiple(boolean multiple)
    {
        this.multiple = multiple;
    }

    public void setStyle(String style)
    {
        this.style = style;
    }

    public String getRows()
    {
        return rows;
    }

    public void setRows(String rows)
    {
        this.rows = rows;
    }

    public int getUnitsPerRow()
    {
        return unitsPerRow;
    }

    public void setUnitsPerRow(int i)
    {
        unitsPerRow = i;
    }

    public boolean isAddNullOption()
    {
        return addNullOption;
    }

    public void setAddNullOption(boolean addNullOption)
    {
        this.addNullOption = addNullOption;
    }

    public boolean isDisabled()
    {
        return disabled;
    }

    public void setDisabled(boolean disabled)
    {
        this.disabled = disabled;
    }

    public String getOnClick()
    {
        return onClick;
    }

    public void setOnClick(String onClick)
    {
        this.onClick = onClick;
    }

    public void display(JspWriter out, boolean isOneLine)
        throws Exception
    {
        StringBuffer disHtml = new StringBuffer();
        if(type == null)
            disHtml.append("type����δ��д��");
        else
        if(name == null)
            disHtml.append("name����δ��д��");
        else
        if(enum_ == null)
            disHtml.append("enum_����δ��д��");
        else
        if(type.toUpperCase().equals("SELECT"))
            displaySelect(disHtml);
        else
        if(type.toUpperCase().equals("RADIO"))
            displayRadio(disHtml);
        else
        if(type.toUpperCase().equals("CHECKBOX"))
            displayCheckbox(disHtml);
        else
            disHtml.append("�����˲���֧�ֵ�type����");
        if(isOneLine)
        {
            String dis = disHtml.toString().replaceAll("\n", "");
            dis = dis.replaceAll("\"", "'");
            out.print(dis);
        } else
        {
            out.println(disHtml.toString());
        }
    }

    public void display(JspWriter out)
        throws Exception
    {
        display(out, false);
    }

    public String display()
        throws Exception
    {
        StringBuffer disHtml = new StringBuffer();
        if(type == null)
            disHtml.append("type����δ��д��");
        else
        if(name == null)
            disHtml.append("name����δ��д��");
        else
        if(enum_ == null)
            disHtml.append("enum_����δ��д��");
        else
        if(type.toUpperCase().equals("SELECT"))
            displaySelect(disHtml);
        else
        if(type.toUpperCase().equals("RADIO"))
            displayRadio(disHtml);
        else
        if(type.toUpperCase().equals("CHECKBOX"))
            displayCheckbox(disHtml);
        else
            disHtml.append("�����˲���֧�ֵ�type����");
        return disHtml.toString();
    }

    public void displaySelect(StringBuffer disHtml)
    {
        disHtml.append("<select");
        disHtml.append(" name=\"" + name + "\"");
        disHtml.append(onChange == null ? "" : " onchange=\"" + onChange + "\"");
        disHtml.append(onFocus == null ? "" : " onfocus=\"" + onFocus + "\"");
        disHtml.append(onBlur == null ? "" : " onblur=\"" + onBlur + "\"");
        disHtml.append(className == null ? "" : " class=\"" + className + "\"");
        disHtml.append(style == null ? "" : " style=\"" + style + "\"");
        disHtml.append(multiple ? " multiple" : "");
        disHtml.append(disabled ? " disabled" : "");
        disHtml.append(">");
        Set keySet = enum_.keySet();
        Iterator keyIterator = keySet.iterator();
        if(addNullOption)
            disHtml.append("\n<option value=\"\">��ѡ�񡭡�</option>");
        int i = 0;
        String key = null;
        String text = null;
        String selected = null;
        for(; keyIterator.hasNext(); disHtml.append(">" + enum_.get(key) + "</option>"))
        {
            key = (String)keyIterator.next();
            if(order != null)
                key = (String)order.get(i++);
            text = (String)enum_.get(key);
            selected = "";
            if(values != null)
                selected = values.contains(key) ? " selected" : "";
            disHtml.append("\n<option value=\"" + key + "\"");
            disHtml.append(selected);
        }

        disHtml.append("</select>");
    }

    public void displayRadio(StringBuffer disHtml)
    {
        Set keySet = enum_.keySet();
        Iterator keyIterator = keySet.iterator();
        int i = 0;
        while(keyIterator.hasNext()) 
        {
            String key = (String)keyIterator.next();
            String text = (String)enum_.get(key);
            String checked = "";
            if(values != null)
                checked = values.contains(key) ? " checked" : "";
            disHtml.append("\n\t\t<input type=\"radio\" name=\"" + name + "\" value=\"" + key + "\" " + checked + " style=\"border: 0px\"" + (disabled ? " disabled" : "") + (onClick != null ? " onclick=\"" + onClick + "\"" : "") + ">" + text + "&nbsp;");
            if(++i % unitsPerRow == 0)
                disHtml.append("<br>");
        }
    }

    public void displayCheckbox(StringBuffer disHtml)
    {
        Set keySet = enum_.keySet();
        Iterator keyIterator = keySet.iterator();
        int i = 0;
        while(keyIterator.hasNext()) 
        {
            String key = (String)keyIterator.next();
            String text = (String)enum_.get(key);
            String checked = "";
            if(values != null)
                checked = values.contains(key) ? " checked" : "";
            disHtml.append("\n\t\t<input type=\"checkbox\" name=\"" + name + "\" value=\"" + key + "\"" + checked + " style=\"border: 0px\"" + (disabled ? " disabled" : "") + (onClick != null ? " onclick=\"" + onClick + "\"" : "") + ">" + text + "&nbsp;");
            if(++i % unitsPerRow == 0)
                disHtml.append("<br>");
        }
    }

    public HashMap getParaEnum_(String paraName)
        throws Exception
    {
        try
        {
            if(Paras.selCache == null)
            {
                WebSelXmlReader webSelXmlReader = new WebSelXmlReader();
                webSelXmlReader.read();
                return (HashMap)Paras.selCache.get(paraName);
            } else
            {
                return (HashMap)Paras.selCache.get(paraName);
            }
        }
        catch(Exception e)
        {
            System.out.println("getParaEnum_():ȡϵͳ���ò����?");
            e.printStackTrace();
            throw e;
        }
    }

    public HashSet getDefaultValues(String paraName)
        throws Exception
    {
        try
        {
            if(Paras.selCache == null)
            {
                WebSelXmlReader webSelXmlReader = new WebSelXmlReader();
                webSelXmlReader.read();
                return (HashSet)Paras.selCache.get(paraName + "_default");
            } else
            {
                return (HashSet)Paras.selCache.get(paraName + "_default");
            }
        }
        catch(Exception e)
        {
            System.out.println("getDefaultValues():ȡϵͳ���ò����?");
            e.printStackTrace();
            throw e;
        }
    }

    public Vector getXMLOrders(String paraName)
        throws Exception
    {
        try
        {
            if(Paras.selCache == null)
            {
                WebSelXmlReader webSelXmlReader = new WebSelXmlReader();
                webSelXmlReader.read();
                return (Vector)Paras.selCache.get(paraName + "_order");
            } else
            {
                return (Vector)Paras.selCache.get(paraName + "_order");
            }
        }
        catch(Exception e)
        {
            System.out.println("getDefaultValues():ȡϵͳ���ò����?");
            e.printStackTrace();
            throw e;
        }
    }

    public static String getParaDesc(String paraName, String paraKey)
        throws Exception
    {
        try
        {
            if(Paras.selCache == null)
            {
                WebSelXmlReader webSelXmlReader = new WebSelXmlReader();
                webSelXmlReader.read();
            }
            if(paraKey == null || paraKey.equals(" ") || paraKey.equals(""))
                return "";
            if(Paras.selCache.get(paraName) == null)
            {
                System.out.println("����" + paraName + " ������");
                return paraKey;
            }
            if(((HashMap)Paras.selCache.get(paraName)).get(paraKey.trim()) == null)
            {
                System.out.println("��Ϊ" + paraName + " ��xml��δ����" + paraKey);
                return paraKey;
            } else
            {
                return (String)((HashMap)Paras.selCache.get(paraName)).get(paraKey.trim());
            }
        }
        catch(Exception e)
        {
            System.out.println("getParaEnum_():ȡϵͳ���ò����?");
            e.printStackTrace();
            throw e;
        }
    }

    public Vector getOrder()
    {
        return order;
    }

    public void setOrder(Vector order)
    {
        this.order = order;
    }
}
